from u8.u8_helper import MssqlHelper

class Department:
    db = None
    table = 'Department'

    def __init__(self, db_name='UFDATA_201_2018'):
        self.db = MssqlHelper(db_name)

    def get(self, name):
        sql = f"select cDepCode,cDepName,cDepFullName from {self.table} where cDepName like '%{name}%'"
        rows = self.db.query_all(sql)
        for row in rows:
            print(f'部门编码：{row[0]}, 部门名称：{row[1]}, 部门全称：{row[2]}')

    def update_saleBillVouch(self, cDepCode, cSBVCode):
        sql = f"update SaleBillVouch set cDepCode='{cDepCode}' where cSBVCode='{cSBVCode}'"
        self.db.update(sql)
        print(f'发票号：{cSBVCode}, 部门已更新')

    def update_saleOrder(self, cDepCode, cSOCode):
        sql = f"update SO_SOMain set cDepCode='{cDepCode}' where cSOCode='{cSOCode}'"
        self.db.update(sql)
        print(f'销售订单：{cSOCode}, 部门已更新')

    def update_dispatchList(self, cDepCode, cDLCode):
        sql = f"update DispatchList set cDepCode='{cDepCode}' where cDLCode='{cDLCode}'"
        self.db.update(sql)
        print(f'发货单：{cDLCode}, 部门已更新')
